class code1 {
    //双指针
    public int findClosest(String[] words, String word1, String word2) {
        int res = Integer.MAX_VALUE;
        //遍历words数组 不断更新p和q的值
        for(int i=0,p = -1,q = -1;i<words.length;i++) {
            if(words[i].equals(word1)) {
                p = i;
            }

            if(words[i].equals(word2)) {
                q = i;
            }

            if(p!=-1 && q!=-1) {
                res = Math.min(res,Math.abs(p-q));
            }
        }
        return res;
    }
}